/* 
 * File:   ClientLauncher.cpp
 * Author: Xi
 *
 * Created on April 7, 2013, 5:11 AM
 */

#include <cstdlib>
#include"Client.h"

using namespace std;

int fd;

int main(int argc, char **argv) {

	if(argc != 2)
	{
		cout << "Usage: ./Client [Server Adress]" << endl;
		return 0;
	}
    ApplicationLayer app;
    DataLinkLayer dl;
    app.setCarrier("client");
    Client c;
    TCPSocket *soc = new TCPSocket();
    fd = soc->conn(12111, argv[1]); /*connection to server*/
    if (fd > 0) {
        cout << "Connected to server!" << endl;

        bool b = c.isReceivedMsg();

        cout << "--------command help--------" << endl;
        cout << "register" << " --register a new account" << endl;
        cout << "login" << " --login by provide user name and password" << endl;
        cout << "list team date" << " --list all games by specify date and team" << endl;
        cout << "book game_id" << " --book a ticket by provide game_id" << endl;
//        cout << "confirm game_id" << "confirm a order by provide game_id again" << endl;
        cout << "pay credit_card" << " --pay for the ticket by provide credit card  number" << endl;
        cout << "view" << " -- view all ordering  history" << endl;
        cout << "echo_debug" << " -- echo all debug information" << endl;
        cout << "hide_debug" << " -- hide all debug information" << endl;
        cout << "error" << " -- set error from 0 - 100, 0 means 0% error and 100 means 100% error" << endl;
        cout << "logoff" << " -- logout" << endl;
		cout << "quit" << " -- quit client" <<endl;
        cout << "-------------------------------------" << endl;
 
        while (true) {
            b = c.isReceivedMsg();
            if (b == true) {
                c.setReceivedMsg(false);
                c.parseInput("", fd);
				if (c.quit){return 0;}
                continue;
            }
            continue;
        }
    } else {

    }
}
